#ifndef LIST_H
#define LIST_H

#include <QObject>
#include <QVector>

class Item;
class Source;

class NameSpace;

class List : public QObject
{
    Q_OBJECT

public:
    typedef QVector<Item*> t_items;

public:
    explicit List();
    virtual ~List();

    const t_items &items() const;

    void setName(const QString &name);
    const QString name() const;

    const bool sumIsValid() const;
    const int sum() const;

    const uint numSources() const;


    const bool addItem(Item *item);
    const bool removeItem(Item *item);

    NameSpace *nameSpace();

    const bool isUpdating() const;

public slots:
    void update();
    void cancel();

signals:
    void modified();
    void updated(
        uint succeeded
    ,   uint failed
    ,   uint skipped);

    void nameChanged(const QString &name);

    void sumChanged(int sum);
    void sumUpdated(int sum);

    void itemAdded(Item *item);
    void itemRemoved(Item *item);

    void numSourcesChanged(uint numSources);

protected slots:
    void item_sourceAdded(Source *source);
    void item_sourceRemoved(Source *source);

    void item_ignoreStateChanged(bool ignored);
    void item_sourceIgnoreStateChanged(bool ignored);

    void item_updated(
        uint succeeded
    ,   uint failed);

protected:
    NameSpace *m_nameSpace;

    QString m_name;
    t_items m_items;

    int m_sum;

    uint m_succeeded;
    uint m_failed;
};

#endif // LIST_H
